package com.ima.web.account.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.ima.web.beans.db.Users;
import com.ima.web.service.UserService;

@Controller
@RequestMapping("/account")
public class AccountsController {

	@Autowired
	private UserService userService;
	
	@RequestMapping(method={RequestMethod.POST,RequestMethod.GET})
	public String accountHome(ModelMap map){
		String username = SecurityContextHolder.getContext().getAuthentication().getName();
		System.out.println();
		System.out.println();
		System.out.println();
		System.out.println();
		System.out.println();
		System.out.println();
		System.out.println("Controller: "+username);
		Users u = userService.getUserData(username);
		System.out.println(u.getEmail());
		System.out.println(u.getPenName());
		map.put("userInfo",u);
		map.put("msg","Account Home");
		
		return "user/userHome";
	}

	@RequestMapping("/test")
	public String accountTest(ModelMap map){
		map.put("msg","url is account/test");
		return "user/userHome";
	}
}
